package com.monkey.thread;

import org.apache.hc.core5.concurrent.DefaultThreadFactory;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * User: zhangqi
 * Date: 2024/8/18
 *
 * @Description:线程池的创建
 */

public class ExecutorCreate {
    public static void main(String[] args) {
        /**
         * 线程池的执行顺序:总结来说就是优先核心线程、阻塞队列次之，最后非核心线程。
         */
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                5,
                10,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(5),
                new DefaultThreadFactory("测试线程池工厂"),
                new ThreadPoolExecutor.CallerRunsPolicy());
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(1111);
            }
        });
        poolExecutor.execute(thread);
        poolExecutor.shutdown();
    }
}
